package com.tjsinfo.tjsoa.worklog.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogExamineBo;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogMainBo;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogExamine;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;


public class InstructionWorkLogFromAction extends Action{
	private IWorkLogExamineBo workLogExamineBo;
	private IWorkLogMainBo workLogMainBo;

	public IWorkLogExamineBo getWorkLogExamineBo() {
		return workLogExamineBo;
	}

	public void setWorkLogExamineBo(IWorkLogExamineBo workLogExamineBo) {
		this.workLogExamineBo = workLogExamineBo;
	}

	public IWorkLogMainBo getWorkLogMainBo() {
		return workLogMainBo;
	}

	public void setWorkLogMainBo(IWorkLogMainBo workLogMainBo) {
		this.workLogMainBo = workLogMainBo;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			String id = request.getParameter("id");
			Integer messageid = 0;
			if(request.getParameter("messageid") != null)
			{
				messageid = Integer.parseInt(request.getParameter("messageid"));	
			}
			if(request.getParameter("start")!=null)
			{
				request.setAttribute("start", 1);
			}
			if(request.getParameter("temp") !=null)
			{
				request.setAttribute("temp", 1);
			}
			List<WorkLogExamine> list =  workLogExamineBo.selectSuddenlyWorkLog(SessionUser.getUserId(request), 0); 
			for (WorkLogExamine workLogExamine : list) {
				if(workLogExamine.getWorkLogMain().getId().equals(id))
				{
					request.setAttribute("start", 1);
				}
			}
			WorkLogMain workLogMain =	workLogMainBo.selectByID(id);
			if(workLogMain == null)
			{
				  response.getWriter().println("<html><head><script language='javascript'>alert('该工作日志已经删除！');</script></head><body></body></html>");
				return mapping.findForward("error");
			}
			request.setAttribute("workLogMain", workLogMain);
			request.setAttribute("messageid", messageid);
			return mapping.findForward("ok");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return mapping.findForward("error");
		}
		
	}
	
}
